﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DHQGHN.PM0.Common.Attributes;

namespace DHQGHN.PM0.Models.Admin
{
    public class ServeyMethodModel
    {
        public string Survey_Method_Id { get; set; }
        [Required(AllowEmptyStrings = false, ErrorMessageResourceName = "Error_HaventPutServeyMothodCodeYet", ErrorMessageResourceType = typeof(Resources.Localization))]
        [Remote("CheckExistServeyCode", "ServeyMethod", ErrorMessage = "Mã Phương thức điều tra đã tồn tại", HttpMethod = "POST", AdditionalFields = "Survey_Method_Id")]
        [StringLength(12, ErrorMessageResourceName = "Error_ServeyMothodCodeLength", ErrorMessageResourceType = typeof(Resources.Localization))]
        [LocalizationDisplay("ServeyMothodCode")]
        [RegularExpression(@"^[a-zA-Z0-9]+[a-zA-Z0-9_]*[a-zA-Z0-9]*$", ErrorMessage = "Mã không đúng định dạng")]
        public string Code { get; set; }
        [Required(AllowEmptyStrings = false, ErrorMessageResourceName = "Error_HaventPutServeyMothodNameYet", ErrorMessageResourceType = typeof(Resources.Localization))]
        [Remote("CheckExistServeyName", "ServeyMethod", ErrorMessage = "Tên Phương thức điều tra đã tồn tại", HttpMethod = "POST", AdditionalFields = "Survey_Method_Id")]
        [StringLength(255, ErrorMessageResourceName = "Error_ServeyMothodNameLength", ErrorMessageResourceType = typeof(Resources.Localization))]
        [LocalizationDisplay("ServeyMothodName")]
        public string Name { get; set; }        
        [StringLength(255, ErrorMessageResourceName = "Error_ServeyMothodDescriptionsLength", ErrorMessageResourceType = typeof(Resources.Localization))]
        [LocalizationDisplay("ServeyMothodDescriptions")]
        public string Descriptions { get; set; }
        public int Deleted { get; set; }
        public int RecordCount { get; set; }
        public ServeyMethodModel()
        {

        }
        
        
        public ServeyMethodModel(DAL.Models.Admin.ServeyMethodModel servey)
        {
            // TODO: Complete member initialization
            this.Survey_Method_Id = servey.Survey_Method_Id;
            this.Code = servey.Code;
            this.Name = servey.Name;
            this.Descriptions = servey.Descriptions;
            this.Deleted = servey.Deleted;
            this.RecordCount = servey.RecordCount;
        }

        internal DAL.Models.Admin.ServeyMethodModel toDALModel()
        {
            return new DAL.Models.Admin.ServeyMethodModel
            {
                Survey_Method_Id = Survey_Method_Id,
                Code = this.Code != null ? this.Code.Trim() : null,
                Name = this.Name != null ? this.Name.Trim() : null,
                Deleted = this.Deleted,
                Descriptions = Descriptions
            };
        }
    }
}